package com.dzf.service.impl;

import com.dzf.entity.Cart;
import com.dzf.mapper.CartMapper;
import com.dzf.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    CartMapper cartMapper;

    @Override
    public List<Cart> findAll(int uid) {
        return cartMapper.findAll(uid);
    }

    @Override
    public void addCart(Cart cart) {
        cartMapper.addCart(cart);
    }

    /**
     * 先更新购物车数据,影响行等于0就添加数据
     * @param cart 购物车
     */
    @Transactional
    @Override
    public void updCart(Cart cart) {
        //更新
        int i = cartMapper.updCart(cart);
        if (i==0)
        {
            //添加
            cartMapper.addCart(cart);
        }
    }

    @Transactional
    @Override
    /**
     * 批量删除，防止出错
     */
    public void deleteMyCart(List<Object> bookid, int uid) {
        cartMapper.deleteMyCart(bookid,uid);
    }


}
